package com.cap.bts.framework.location.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cap.bts.framework.common.constant.CommonErrorConstants;
import com.cap.bts.framework.common.exception.AppException;
import com.cap.bts.framework.location.dao.LocationInfoDao;
import com.cap.bts.framework.location.domain.LocationInfo;
import com.cap.bts.framework.location.service.LocationInfoService;

/**
 * @author: huiwu
 * @data：Oct 14, 2014
 * 
 */
@Transactional(rollbackFor=AppException.class)
@Service
public class LocationInfoServiceImpl implements LocationInfoService {
    @Autowired
    LocationInfoDao locationInfoDao;
    
    @Override
    public void addLocationInfo(LocationInfo locationinfo) throws AppException {
        try {
            locationInfoDao.save(locationinfo);
        } catch (Exception e) {
            throw new AppException(CommonErrorConstants.SYSTEM_ERROR,
                CommonErrorConstants.SYSTEM_EXCEPTION_MESSAGE_PREFIX
                                + e.getMessage());
        }
    }

    @Override
    public LocationInfo deleteLocationInfo(Long id) throws AppException {
        try {
            LocationInfo locationinfo = locationInfoDao.findById(id);
            locationInfoDao.remove(id);
            return locationinfo;
        } catch (Exception e) {
            throw new AppException(CommonErrorConstants.SYSTEM_ERROR,
                CommonErrorConstants.SYSTEM_EXCEPTION_MESSAGE_PREFIX
                                + e.getMessage());
        }
    }

    @Override
    public void updateLocationInfo(LocationInfo locationinfo) throws AppException {
        try {
            locationInfoDao.update(locationinfo);
        } catch (Exception e) {
            throw new AppException(CommonErrorConstants.SYSTEM_ERROR,
                CommonErrorConstants.SYSTEM_EXCEPTION_MESSAGE_PREFIX
                                + e.getMessage());
        }
    }

    @Override
    public LocationInfo getLocationInfoById(Long id) throws AppException {
        try {
            return locationInfoDao.findById(id);
        } catch (Exception e) {
            throw new AppException(CommonErrorConstants.SYSTEM_ERROR,
                CommonErrorConstants.SYSTEM_EXCEPTION_MESSAGE_PREFIX
                                + e.getMessage());
        }
    }

    @Override
    public List<LocationInfo> getLocationInfoByLocationNo(String locationNo) throws AppException {
        try {
            return locationInfoDao.getLocationInfoByLocationNo(locationNo);
        } catch (Exception e) {
            throw new AppException(CommonErrorConstants.SYSTEM_ERROR,
                CommonErrorConstants.SYSTEM_EXCEPTION_MESSAGE_PREFIX
                                + e.getMessage());
        }
    }

    @Override
    public List<LocationInfo> getAllLocationInfo() throws AppException {
        try {
            return locationInfoDao.getAll();
        } catch (Exception e) {
            throw new AppException(CommonErrorConstants.SYSTEM_ERROR,
                CommonErrorConstants.SYSTEM_EXCEPTION_MESSAGE_PREFIX
                                + e.getMessage());
        }
    }

}
